package com.cug.nageoffer.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cug.nageoffer.model.entity.Interview;
import com.cug.nageoffer.model.vo.Result;
import com.cug.nageoffer.model.vo.ResultCodeEnum;
import com.cug.nageoffer.user.mapper.InterviewMapper;
import com.cug.nageoffer.user.service.InterviewService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class InterviewServiceImpl extends ServiceImpl<InterviewMapper, Interview> implements InterviewService {
    @Override
    public Result<String> reserve(Interview requestParam) {
        requestParam.setStatus(0);
        save(requestParam);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Override
    public Result<List<Integer>> count(Long id) {
        List<Interview> interviewList = query().eq("seeker_id", id).list();
        int num0=0,num1=0,num2=0;
        for (Interview interview : interviewList) {
            switch (interview.getStatus()) {
                case 0 -> num0++;
                case 1 -> num1++;
                case 2 -> num2++;
            }
        }
        List<Integer> countList = new ArrayList<>(Arrays.asList(num0, num1, num2));
        return Result.build(countList,ResultCodeEnum.SUCCESS);
    }

    @Override
    public Result<String> cancel(Interview requestParam) {
        update().eq("hr_id",requestParam.getHrId())
                .eq("seeker_id",requestParam.getSeekerId())
                .eq("interview_time",requestParam.getInterviewTime())
                .eq("status",0).set("status",2).update();
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Override
    public Result<String> alter(Interview requestParam) {
        update().eq("hr_id",requestParam.getHrId())
                .eq("seeker_id",requestParam.getSeekerId())
                .eq("status",0)
                .set("interview_time",requestParam.getInterviewTime()).update();
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Override
    public Result<String> finish(Interview requestParam) {
        update().eq("hr_id",requestParam.getHrId())
                .eq("seeker_id",requestParam.getSeekerId())
                .eq("interview_time",requestParam.getInterviewTime())
                .eq("status",0).set("status",1).update();
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
